<template>
	<xbd-pages-content title="员工考勤统计">
		<template #content>
			<view class="staff-statistics">
				<view class="header">
					<view class="search">
						<picker mode="multiSelector"
							@columnchange="bindMultiPickerColumnChange"
							:range="multiArray"
							:value="multiIndex"
							range-key="name"
							@change="changeSelector"
						>
							<view class="select">
								<image class="img" src="@/static/images/common/apartment.svg" mode=""></image>
								<view class="text">{{ department }}</view>
							</view>
						</picker>
						<view class="ipt-view" @click="clickSearch">
							{{ username }}
						</view>
					</view>
					<view class="staff-info" v-if="username !== '搜索员工姓名'">
						<image class="img" src="@/static/images/common/car.png" mode=""></image>
						<view class="info">
							<view class="name">
								{{ username }}
							</view>
							<view class="department">
								{{ department }}
							</view>
						</view>
					</view>
				</view>
				<view class="date-card" v-if="username !== '搜索员工姓名'">
					<xbd-date :date.sync="date"></xbd-date>
				</view>
				<work-statistics :info="statistics" v-if="username !== '搜索员工姓名'"></work-statistics>
			</view>
		</template>
	</xbd-pages-content>
</template>

<script>
	import WorkStatistics from '@/components/workattendance/WorkStatistics.vue';
	const dayjs = require('dayjs');
	const date = dayjs(new Date()).format('YYYY-MM'); // '25/01/2019'
	export default {
		data() {
			return {
				multiIndex: 0,
				multiArray: [
					[{name:'总经办总经办总经办', id: 1}, {name:'营销', id: 2}, {name:'营销', id: 3}],
					[{name:'张三张三张三张三张三', id: 1}, {name:'李四', id: 2}, {name:'王五', id: 3}],
					[{name:'张三张三张三张三张三', id: 1}, {name:'李四', id: 2}, {name:'王五', id: 3}]
				],
				department: '全部部门',
				username: '搜索员工姓名',
				date,
				statistics: {
					a: 9.4,
					b: 23,
					c: 21,
					d: 9,
					e: 0,
					f: 0,
					g: 0,
					h: 0,
					i: 4,
					j: 2
				}
			};
		},
		components: {
			WorkStatistics
		},
		methods: {
			bindMultiPickerColumnChange(e) {
				if (e.detail.column === 0) {
					console.log(this.multiArray[e.detail.column][e.detail.column]);
					this.$set(this.multiArray, 1, [{name:'张一', id: 1}, {name:'李二', id: 2}, {name:'王三', id: 3}]);
				}
			},
			changeSelector(e) {
				console.log(e);
				this.multiIndex = e.detail.value;
				this.department = this.multiArray[0][this.multiIndex[0]].name;
				this.username = this.multiArray[1][this.multiIndex[1]].name;
			},
			clickSearch() {
				uni.navigateTo({
					url: './searchstaff',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			}
 		},
		onLoad() {
			uni.$on('searchVal', (val) => {
				this.department = val.department;
				this.username = val.name;
			})
		}
	}
</script>

<style lang="scss" scoped>
	.staff-statistics {
		.header {
			margin-bottom: 10px;
			padding: 20px 50rpx;
			
			background-color: #FFFFFF;
		}
		.search {
			display: flex;
			justify-content: space-between;
			.select {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 20rpx;
				width: 220rpx;
				height: 32px;
				line-height: 30px;
				border: 1px solid #E9ECF7;
				
				font-size: 14px;
				
				color: #999999;
				
				box-sizing: border-box;
				.img {
					width: 28rpx;
					height: 28rpx;
					margin-right: 20rpx;
				}
				.text {
					flex: 1;
					overflow: hidden;/*超出部分隐藏*/
					text-overflow:ellipsis;/* 超出部分显示省略号 */
					white-space: nowrap;/*规定段落中的文本不进行换行 */
				}
			}
			.ipt-view {
				width: 410rpx;
				height: 32px;
				padding: 0 20rpx;
				line-height: 30px;
				border: 1px solid #E9ECF7;
				
				font-size: 14px;
				
				color: #999999;
				box-sizing: border-box;
			}
		}
		.staff-info {
			display: flex;
			
			margin-top: 20px;
			.img {
				width: 100rpx;
				height: 100rpx;
				
				border-radius: 50%;
				margin-right: 50rpx;
			}
			.info {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.name {
					font-size: 14px;
					
					color: $uni-color-primary;
				}
				.department {
					font-size: 12px;
					
					color: $uni-text-color;
				}
			}
		}
		.date-card {
			padding: 20px 50rpx;
			margin-bottom: 10px;
			
			background-color: #FFFFFF;
		}
	}
</style>
